home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / JFileChooser.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  41.6 KB  |  1,368 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)JFileChooser.java    1.40 98/08/26
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package javax.swing;
  16.  
  17. import javax.swing.event.*;
  18. import javax.swing.filechooser.*;
  19. import javax.swing.plaf.FileChooserUI;
  20.  
  21. import javax.accessibility.*;
  22.  
  23. import java.io.File;
  24. import java.io.ObjectOutputStream;
  25. import java.io.ObjectInputStream;
  26. import java.io.IOException;
  27.  
  28. import java.util.Vector;
  29. import java.awt.Component;
  30. import java.awt.Container;
  31. import java.awt.BorderLayout;
  32. import java.awt.Frame;
  33. import java.awt.event.*;
  34.  
  35. /**
  36.  * JFileChooser provides a simple mechanism for the user to chooser a file.
  37.  *
  38.  * The following pops up a file chooser in the users home directory that
  39.  * only sees .jpg and .gif images:
  40.  *    JFileChooser chooser = new JFileChooser();
  41.  *    ExtensionFileFilter filter = new ExtensionFileFilter();
  42.  *    filter.addExtension("jpg");
  43.  *    filter.addExtension("gif");
  44.  *    filter.setDescription("JPG & GIF Images");
  45.  *    chooser.setFileFilter(filter);
  46.  *    int returnVal = chooser.showOpenDialog(parent);
  47.  *    if(returnVal == JFileChooser.APPROVE_OPTION) {
  48.  *       System.out.println("You chose to open this file: " +
  49.  *            chooser.getSelectedFile().getName());
  50.  *    }
  51.  *
  52.  * @beaninfo
  53.  *   attribute: isContainer false
  54.  *
  55.  * @version 1.40 08/26/98
  56.  * @author Jeff Dinkins
  57.  *
  58.  */
  59. public class JFileChooser extends JComponent implements Accessible {
  60.  
  61.     /**
  62.      * @see #getUIClassID
  63.      * @see #readObject
  64.      */
  65.     private static final String uiClassID = "FileChooserUI";
  66.  
  67.  
  68.     // ************************
  69.     // ***** Dialog Types *****
  70.     // ************************
  71.  
  72.     /**
  73.      * Type value indicating that the FileChooser supports an "Open"
  74.      * file operation.
  75.      */
  76.     public static final int OPEN_DIALOG = 0;
  77.  
  78.     /**
  79.      * Type value indicating that the FileChooser supports a "Save"
  80.      * file operation.
  81.      */
  82.     public static final int SAVE_DIALOG = 1;
  83.  
  84.     /**
  85.      * Type value indicating that the FileChooser supports a developer
  86.      * sepcified file operation.
  87.      */
  88.     public static final int CUSTOM_DIALOG = 2;
  89.  
  90.  
  91.     // ********************************
  92.     // ***** Dialog Return Values *****
  93.     // ********************************
  94.  
  95.     /**
  96.      * Return value if cancel is chosen.
  97.      */
  98.     public static final int CANCEL_OPTION = 1;
  99.  
  100.     /**
  101.      * Return value if approve (yes, ok) is chosen.
  102.      */
  103.     public static final int APPROVE_OPTION = 0;
  104.  
  105.     /**
  106.      * Return value if an error occured.
  107.      */
  108.     public static final int ERROR_OPTION = -1;
  109.  
  110.  
  111.     // **********************************
  112.     // ***** FileChooser properties *****
  113.     // **********************************
  114.  
  115.  
  116.     /** Instruction to display only files. */
  117.     public static final int FILES_ONLY = 0;
  118.     /** Instruction to display only directories. */
  119.     public static final int DIRECTORIES_ONLY = 1;
  120.     /** Instruction to display both files and directories. */
  121.     public static final int FILES_AND_DIRECTORIES = 2;
  122.  
  123.     /** Instruction to cancel the current selection. */
  124.     public static final String CANCEL_SELECTION = "CancelSelection";
  125.     /** Instruction to approve the current selection (Same as pressing yes or ok.) */
  126.     public static final String APPROVE_SELECTION = "ApproveSelection";
  127.  
  128.     /** Identifies change in the text on the approve (yes, ok) button. */
  129.     public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY = "ApproveButtonTextChangedProperty";
  130.     /**  Identifies change in the tooltip text for the approve (yes, ok) button . */
  131.     public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY = "ApproveButtonToolTipTextChangedProperty";
  132.     /**  Identifies change in the mnemonic for the approve (yes, ok) button . */
  133.     public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY = "ApproveButtonMnemonicChangedProperty";
  134.  
  135.     /** Identifies user's directory change. */
  136.     public static final String DIRECTORY_CHANGED_PROPERTY = "directoryChanged";
  137.     /** Identifes change in user's single-file selection. */
  138.     public static final String SELECTED_FILE_CHANGED_PROPERTY = "SelectedFileChangedProperty";
  139.     /** Identifes change in user's multiple-file selection. */
  140.     public static final String SELECTED_FILES_CHANGED_PROPERTY = "SelectedFilesChangedProperty";
  141.  
  142.     /** Enables multiple-file selections. */
  143.     public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY = "fileFilterChanged";
  144.  
  145.     /** Says that a different object is being used to find available drives on the system. */
  146.     public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY = "FileSystemViewChanged";
  147.  
  148.     /** Says that a different object is being used to retrieve file information. */
  149.     public static final String FILE_VIEW_CHANGED_PROPERTY = "fileViewChanged";
  150.     /** Identifies a change in the display-hidden-files property. */
  151.     public static final String FILE_HIDING_CHANGED_PROPERTY = "FileHidingChanged";
  152.  
  153.     /** User changed the kind of files to display.*/
  154.     public static final String FILE_FILTER_CHANGED_PROPERTY = "fileFilterChanged";
  155.  
  156.     /** Identifies a change in the kind of selection (single, multiple, etc.). */
  157.     public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY = "fileSelectionChanged";
  158.     /** Says that a different accessory component is in use. (For example, to preview files.) */
  159.     public static final String ACCESSORY_CHANGED_PROPERTY = "AccessoryChangedProperty";
  160.  
  161.     /** Identifies a change in the dialog title. */
  162.     public static final String DIALOG_TITLE_CHANGED_PROPERTY = "DialogTitleChangedProperty";
  163.     /**
  164.      * Identifies a change in the type of files displayed (files only,
  165.      * directories only, or both files and directories. 
  166.      */
  167.     public static final String DIALOG_TYPE_CHANGED_PROPERTY = "DialogTypeChangedProperty";
  168.     /** 
  169.      * Identifies a change in the list of predefined file filters
  170.      * the user can choose from
  171.      */
  172.     public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY = "ChoosableFileFilterChangedProperty";
  173.  
  174.     // ******************************
  175.     // ***** instance variables *****
  176.     // ******************************
  177.  
  178.     private String dialogTitle = null;
  179.     private String approveButtonText = null;
  180.     private String approveButtonToolTipText = null;
  181.     private int approveButtonMnemonic = 0;
  182.  
  183.     private ActionListener actionListener = null;
  184.  
  185.     private Vector filters = new Vector(5);
  186.     private JDialog dialog = null;
  187.     private int dialogType = OPEN_DIALOG;
  188.     private int returnValue = ERROR_OPTION;
  189.     private JComponent accessory = null;
  190.  
  191.     private FileView fileView = null;
  192.     private FileView uiFileView = null;
  193.  
  194.     private boolean useFileHiding = true;
  195.  
  196.     private int fileSelectionMode = FILES_ONLY;
  197.  
  198.     private boolean multiSelectionEnabled = false;
  199.  
  200.     private FileFilter fileFilter = null;
  201.  
  202.     private FileSystemView fileSystemView = null;
  203.  
  204.     private File currentDirectory = null;
  205.     private File selectedFile = null;
  206.     private File[] selectedFiles;
  207.  
  208.     // *************************************
  209.     // ***** JFileChooser Constructors *****
  210.     // *************************************
  211.  
  212.     /**
  213.      * Creates a JFileChooser pointing to the user's home directory.
  214.      */
  215.     public JFileChooser() {
  216.     this((File) null, (FileSystemView) null);
  217.     }
  218.     
  219.     /**
  220.      * Creates a JFileChooser using the given path. Passing in a null
  221.      * string causes the file chooser to point to the users home directory.
  222.      *
  223.      * @param path  a String giving the path to a file or directory
  224.      */
  225.     public JFileChooser(String currentDirectoryPath) {
  226.     this(currentDirectoryPath, (FileSystemView) null);
  227.     }
  228.  
  229.     /**
  230.      * Creates a JFileChooser using the given File as the path. Passing
  231.      * in a null file causes the file chooser to point to the users's
  232.      * home directory.
  233.      *
  234.      * @param directory  a File object specifying the path to a file 
  235.      *                   or directory
  236.      */
  237.     public JFileChooser(File currentDirectory) {
  238.     this(currentDirectory, (FileSystemView) null);
  239.     }
  240.  
  241.     /**
  242.      * Creates a JFileChooser using the given FileSystemView
  243.      */
  244.     public JFileChooser(FileSystemView fsv) {
  245.     this((File) null, fsv);
  246.     }
  247.  
  248.  
  249.     /**
  250.      * Creates a JFileChooser using the given current directory and FileSystemView
  251.      */
  252.     public JFileChooser(File currentDirectory, FileSystemView fsv) {
  253.     setup(fsv);
  254.     setCurrentDirectory(currentDirectory);
  255.     }
  256.  
  257.     /**
  258.      * Creates a JFileChooser using the given current directory path and FileSystemView
  259.      */
  260.     public JFileChooser(String currentDirectoryPath, FileSystemView fsv) {
  261.     setup(fsv);
  262.     if(currentDirectoryPath == null) {
  263.         setCurrentDirectory(null);
  264.         } else {
  265.         setCurrentDirectory(fileSystemView.createFileObject(currentDirectoryPath));
  266.     }
  267.     }
  268.  
  269.     /**
  270.      * Perform common constructor initialization and setup
  271.      */
  272.     protected void setup(FileSystemView view) {
  273.     if(view == null) {
  274.         view = FileSystemView.getFileSystemView();
  275.         }
  276.     setFileSystemView(view);
  277.     updateUI(); 
  278.     setFileFilter(getAcceptAllFileFilter());
  279.     }
  280.  
  281.  
  282.     // *****************************
  283.     // ****** File Operations ******
  284.     // *****************************
  285.  
  286.     /**
  287.      * Returns the selected file. This can be set either by the
  288.      * programmer via setFile() or by a user action, such as
  289.      * either typing the filename int the UI or selecting the
  290.      * file from a list in the UI.
  291.      * 
  292.      * @see #setSelectedFile
  293.      * @return the selected file
  294.      */
  295.     public File getSelectedFile() {
  296.     return selectedFile;
  297.     }
  298.  
  299.     /**
  300.      * Sets the selected file. If the file's parent directory is
  301.      * not the current directory, it changed the current directory
  302.      * to be the files parent directory.
  303.      *
  304.      * @beaninfo
  305.      *   preferred: true
  306.      *       bound: true
  307.      *
  308.      * @see #getSelectedFile
  309.      *
  310.      * @param selectedFile the selected file 
  311.      */
  312.     public void setSelectedFile(File selectedFile) {
  313.     // PENDING(jeff) - make sure that the file's path is
  314.     // in the current directory. If not, change the current
  315.     // directory to the file's path. 
  316.     File oldValue = this.selectedFile;
  317.     this.selectedFile = selectedFile;
  318.     if(selectedFile != null) {
  319.         ensureFileIsVisible(selectedFile);
  320.     }
  321.     firePropertyChange(SELECTED_FILE_CHANGED_PROPERTY, oldValue, this.selectedFile);
  322.     }
  323.  
  324.     /**
  325.      * Returns a list of selected files if the filechooser is
  326.      * set to allow multi-selection.
  327.      */
  328.     public File[] getSelectedFiles() {
  329.     if(selectedFiles == null) {
  330.         return new File[0];
  331.     } else {
  332.         return (File[]) selectedFiles.clone();
  333.     }
  334.     }
  335.  
  336.     /**
  337.      * Sets the list of selected files if the filechooser is
  338.      * set to allow multi-selection.
  339.      *
  340.      * @beaninfo
  341.      *       bound: true
  342.      * description: the list of selected files if the chooser is in multi-selection mode
  343.      */
  344.     public void setSelectedFiles(File[] selectedFiles) {
  345.     File[] oldValue = this.selectedFiles;
  346.     this.selectedFiles = selectedFiles;
  347.     firePropertyChange(SELECTED_FILES_CHANGED_PROPERTY, oldValue, this.selectedFiles);
  348.     }
  349.  
  350.     /**
  351.      * Returns the current directory. 
  352.      *
  353.      * @return the current directory
  354.      * @see #setCurrentDirectory
  355.      */
  356.     public File getCurrentDirectory() {
  357.     return currentDirectory;
  358.     }
  359.  
  360.     /**
  361.      * Sets the current directory. Passing in null sets the filechooser
  362.      * to point to the users's home directory.
  363.      *
  364.      * If the file passed in as currentDirectory is not a directory, the
  365.      * parent of the file will be used as the currentDirectory. If the
  366.      * parent is not traversable, then it will walk up the parent tree
  367.      * until it finds a traversable direcotry, or hits the root of the
  368.      * file system.
  369.      *
  370.      * @beaninfo
  371.      *   preferred: true
  372.      *       bound: true
  373.      * description: the directory that the FileChooser is showing files of
  374.      *
  375.      * @param currentDirectory the current directory to point to
  376.      * @see #getCurrentDirectory
  377.      */
  378.     public void setCurrentDirectory(File dir) {
  379.     if((this.currentDirectory == dir) && (dir != null)) {
  380.         return;
  381.     }
  382.  
  383.     File oldValue = this.currentDirectory;
  384.  
  385.     if(dir == null) {
  386.         this.currentDirectory = getFileSystemView().getHomeDirectory();
  387.     } else {
  388.         File prev = null;
  389.         while(!isTraversable(dir) && prev != dir && !getFileSystemView().isRoot(dir)) {
  390.         prev = dir;
  391.         dir = getFileSystemView().getParentDirectory(dir);
  392.         }
  393.         this.currentDirectory = dir;
  394.     }
  395.  
  396.     firePropertyChange(DIRECTORY_CHANGED_PROPERTY, oldValue, this.currentDirectory);
  397.     }
  398.  
  399.     /**
  400.      * Changes the directory to be set to the parent of the
  401.      * current directory. 
  402.      *
  403.      * @see #getCurrentDirectory
  404.      */
  405.     public void changeToParentDirectory() {
  406.     File oldValue = getCurrentDirectory();
  407.     setCurrentDirectory(getFileSystemView().getParentDirectory(oldValue));
  408.     }
  409.  
  410.     /**
  411.      * Tells the UI to rescan it's files list from the current directory.
  412.      */
  413.     public void rescanCurrentDirectory() {
  414.         getUI().rescanCurrentDirectory(this);
  415.     }
  416.  
  417.     /**
  418.      * Make sure that the specified file is viewable, and
  419.      * not hidden.
  420.      *
  421.      * @param f  a File object
  422.      */
  423.     public void ensureFileIsVisible(File f) {
  424.         getUI().ensureFileIsVisible(this, f);
  425.     }
  426.  
  427.     // **************************************
  428.     // ***** FileChooser Dialog methods *****
  429.     // **************************************
  430.  
  431.     /**
  432.      * Pops up an "Open File" file chooser dialog. Note that the
  433.      * text that appears in the approve button is determined by
  434.      * the L&F.
  435.      *
  436.      *
  437.      * @return   the return state of the filechooser on popdown:
  438.      *             CANCEL_OPTION, APPROVE_OPTION
  439.      */
  440.     public int showOpenDialog(Component parent) {
  441.     setDialogType(OPEN_DIALOG);
  442.     return showDialog(parent, null);
  443.     }
  444.  
  445.     /**
  446.      * Pops up a "Save File" file chooser dialog. Note that the
  447.      * text that appears in the approve button is determined by
  448.      * the L&F.
  449.      *
  450.      * @return   the return state of the filechooser on popdown:
  451.      *             CANCEL_OPTION, APPROVE_OPTION
  452.      */
  453.     public int showSaveDialog(Component parent) {
  454.     setDialogType(SAVE_DIALOG);
  455.     return showDialog(parent, null);
  456.     }
  457.  
  458.     /**
  459.      * Pops a custom file chooser dialog with a custom ApproveButton.
  460.      *
  461.      * e.g. filechooser.showDialog(parentWindow, "Run Application");
  462.      * would pop up a filechooser with a "Run Application" button
  463.      * (instead of the normal "Save" or "Open" button).
  464.      *
  465.      * Alternatively, the following code will do the same thing:
  466.      *    JFileChooser chooser = new JFileChooser(null);
  467.      *    chooser.setApproveButtonText("Run Application");
  468.      *    chooser.showDialog(this, null);
  469.      * 
  470.      * PENDING(jeff) - the following method should be added to the api:
  471.      *      showDialog(Component parent);
  472.      *
  473.      * @param   approveButtonText the text of the ApproveButton
  474.      * @return  the return state of the filechooser on popdown:
  475.      *             CANCEL_OPTION, APPROVE_OPTION
  476.      */
  477.     public int showDialog(Component parent, String approveButtonText) {
  478.     if(approveButtonText != null) {
  479.         setApproveButtonText(approveButtonText);
  480.         setDialogType(CUSTOM_DIALOG);
  481.     }
  482.  
  483.         Frame frame = parent instanceof Frame ? (Frame) parent
  484.               : (Frame)SwingUtilities.getAncestorOfClass(Frame.class, parent);
  485.  
  486.     String title = null;
  487.  
  488.     if(getDialogTitle() != null) {
  489.         title = dialogTitle;
  490.     } else {
  491.         title = getUI().getDialogTitle(this);
  492.     }
  493.  
  494.         dialog = new JDialog(frame, title, true);
  495.         Container contentPane = dialog.getContentPane();
  496.         contentPane.setLayout(new BorderLayout());
  497.         contentPane.add(this, BorderLayout.CENTER);
  498.  
  499.         dialog.pack();
  500.         dialog.setLocationRelativeTo(parent);
  501.  
  502.         dialog.show();
  503.     return returnValue;
  504.     }
  505.  
  506.     // **************************
  507.     // ***** Dialog Options *****
  508.     // **************************
  509.  
  510.     /**
  511.      * Returns the type of this dialog.
  512.      *
  513.      * @return   the type of dialog to be displayed:
  514.      *           OPEN_DIALOG, SAVE_DIALOG, CUSTOM_DIALOG
  515.      *
  516.      * @see #setDialogType
  517.      */
  518.     public int getDialogType() {
  519.     return dialogType;
  520.     }
  521.  
  522.     /**
  523.      * Sets the type of this dialog. Use OPEN_DIALOG when you want to
  524.      * bring up a filechooser that the user can use to open a file. Likewise,
  525.      * use SAVE_DIALOG for letting the user choose a file for saving.
  526.      *
  527.      * Use CUSTOM_DIALOG when you want to use the filechooser in a context
  528.      * other than "Open" or "Save". For instance, you might want to bring up
  529.      * a filechooser that allows the user to choose a file to execute. Note that
  530.      * you normally would not need to set the FileChooser to use CUSTOM_DIALOG
  531.      * since a call to setApproveButtonText does this for you.
  532.      *
  533.      * @param dialogType the type of dialog to be displayed:
  534.      *                   OPEN_DIALOG, SAVE_DIALOG, CUSTOM_DIALOG
  535.      *
  536.      * @beaninfo
  537.      *   preferred: true
  538.      *       bound: true
  539.      * description: The type (open, save, custom) of the FileChooser
  540.      *        enum: 
  541.      *              OPEN_DIALOG JFileChooser.OPEN_DIALOG
  542.      *              SAVE_DIALOG JFileChooser.SAVE_DIALOG
  543.      *              CUSTOM_DIALOG JFileChooser.CUSTOM_DIALOG
  544.      *
  545.      * @see #getDialogType
  546.      * @see #setApproveButtonText
  547.      */ 
  548.     // PENDING(jeff) - fire button text change property
  549.     public void setDialogType(int dialogType) {
  550.     if(this.dialogType == dialogType) {
  551.         return;
  552.     }
  553.     if(!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG || dialogType == CUSTOM_DIALOG)) {
  554.         throw new IllegalArgumentException("Incorrect Dialog Type: " + dialogType);
  555.     }
  556.     int oldValue = this.dialogType;
  557.     this.dialogType = dialogType;
  558.     if(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG) {
  559.         setApproveButtonText(null);
  560.     }
  561.     firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType);
  562.     }
  563.  
  564.     /**
  565.      * Sets the string that goes in the FileChooser window's title bar.
  566.      *
  567.      * @beaninfo
  568.      *   preferred: true
  569.      *       bound: true
  570.      * description: The title of the FileChooser dialog window
  571.      *
  572.      * @see #getDialogTitle
  573.      *
  574.      */
  575.     public void setDialogTitle(String dialogTitle) {
  576.     String oldValue = this.dialogTitle;
  577.     this.dialogTitle = dialogTitle;
  578.     if(dialog != null) {
  579.         dialog.setTitle(dialogTitle);
  580.     }
  581.     firePropertyChange(DIALOG_TITLE_CHANGED_PROPERTY, oldValue, dialogTitle);
  582.     }
  583.  
  584.     /**
  585.      * Gets the string that goes in the FileChooser's titlebar.
  586.      *
  587.      * @see #setDialogTitle
  588.      */
  589.     public String getDialogTitle() {
  590.     return dialogTitle;
  591.     }
  592.  
  593.     // ************************************
  594.     // ***** FileChooser View Options *****
  595.     // ************************************
  596.  
  597.  
  598.  
  599.     /**
  600.      * Sets the tooltip text used in the ApproveButton.
  601.      * If null, the UI object will determine the button's text.
  602.      *
  603.      * @beaninfo
  604.      *   preferred: true
  605.      *       bound: true
  606.      * description: The tooltip text for the ApproveButton
  607.      *
  608.      * @return the text used in the ApproveButton
  609.      *
  610.      * @see #setApproveButtonText
  611.      * @see #setDialogType
  612.      * @see #showDialog
  613.      */ 
  614.     public void setApproveButtonToolTipText(String toolTipText) {
  615.     if(approveButtonToolTipText == toolTipText) {
  616.         return;
  617.     }
  618.     String oldValue = approveButtonToolTipText;
  619.     approveButtonToolTipText = toolTipText;
  620.     setDialogType(CUSTOM_DIALOG);
  621.     firePropertyChange(APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY, oldValue, approveButtonToolTipText);
  622.     }
  623.  
  624.  
  625.     /**
  626.      * Returns the tooltip text used in the ApproveButton.
  627.      * If null, the UI object will determine the button's text.
  628.      *
  629.      * @return the text used in the ApproveButton
  630.      *
  631.      * @see #setApproveButtonText
  632.      * @see #setDialogType
  633.      * @see #showDialog
  634.      */ 
  635.     public String getApproveButtonToolTipText() {
  636.     return approveButtonToolTipText;
  637.     }
  638.  
  639.     /**
  640.      * Returns the approve button's mnemonic.
  641.      * @return an int value for the mnemonic key
  642.      *
  643.      * @see #setApproveButtonMnemonic
  644.      */
  645.     public int getApproveButtonMnemonic() {
  646.     return approveButtonMnemonic;
  647.     }
  648.  
  649.     /**
  650.      * Sets the approve button's mnemonic using a numeric keycode.
  651.      * @param an int value for the mnemonic key
  652.      *
  653.      * @beaninfo
  654.      *   preferred: true
  655.      *       bound: true
  656.      * description: The mnemonic key accelerator for the ApproveButton
  657.      *
  658.      * @see #getApproveButtonMnemonic
  659.      */
  660.     public void setApproveButtonMnemonic(int mnemonic) {
  661.     if(approveButtonMnemonic == mnemonic) {
  662.        return;
  663.     }
  664.     int oldValue = approveButtonMnemonic;
  665.     approveButtonMnemonic = mnemonic;
  666.     firePropertyChange(APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY, oldValue, approveButtonMnemonic);
  667.     }
  668.  
  669.     /**
  670.      * Sets the approve button's mnemonic using a character.
  671.      * @param an char value for the mnemonic key
  672.      *
  673.      * @see #getApproveButtonMnemonic
  674.      */
  675.     public void setApproveButtonMnemonic(char mnemonic) {
  676.         int vk = (int) mnemonic;
  677.         if(vk >= 'a' && vk <='z') {
  678.         vk -= ('a' - 'A');
  679.     }
  680.         setApproveButtonMnemonic(vk);
  681.     }
  682.  
  683.  
  684.     /**
  685.      * Sets the text used in the ApproveButton in the FileChooserUI.
  686.      *
  687.      * @beaninfo
  688.      *   preferred: true
  689.      *       bound: true
  690.      * description: The text that goes in the AprroveButton
  691.      *
  692.      * @param approveButtonText the text used in the ApproveButton
  693.      *
  694.      * @see #getApproveButtonText
  695.      * @see #setDialogType
  696.      * @see #showDialog
  697.      */ 
  698.     // PENDING(jeff) - have ui set this on dialog type change
  699.     public void setApproveButtonText(String approveButtonText) {
  700.     if(this.approveButtonText == approveButtonText) {
  701.         return;
  702.     }
  703.     String oldValue = this.approveButtonText;
  704.     this.approveButtonText = approveButtonText;
  705.     firePropertyChange(APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, oldValue, approveButtonText);
  706.     }
  707.  
  708.     /**
  709.      * Returns the text used in the ApproveButton in the FileChooserUI.
  710.      * If null, the UI object will determine the button's text.
  711.      *
  712.      * Typically, this would be "Open" or "Save".
  713.      *
  714.      * @return the text used in the ApproveButton
  715.      *
  716.      * @see #setApproveButtonText
  717.      * @see #setDialogType
  718.      * @see #showDialog
  719.      */ 
  720.     public String getApproveButtonText() {
  721.     return approveButtonText;
  722.     }
  723.  
  724.     /**
  725.      * Gets the list of user choosable file filters
  726.      *
  727.      * @return a FileFilter array containing all the choosable
  728.      *         file filters
  729.      *
  730.      * @ see #addChoosableFileFilter
  731.      * @ see #removeChoosableFileFilter
  732.      * @ see #resetChoosableFileFilter
  733.      */ 
  734.     public FileFilter[] getChoosableFileFilters() {
  735.     FileFilter[] filterArray = new FileFilter[filters.size()];
  736.     filters.copyInto(filterArray);
  737.     return filterArray;
  738.     }
  739.  
  740.     /**
  741.      * Adds a filter to the list of user choosable file filters.
  742.      * 
  743.      * @param filter the FileFilter to add to the choosable file
  744.      *               filter list
  745.      *
  746.      * @beaninfo
  747.      *   preferred: true
  748.      *       bound: true
  749.      * description: Adds a filter to the list of user choosable file filters.
  750.      *
  751.      * @ see #getChoosableFileFilters
  752.      * @ see #removeChoosableFileFilter
  753.      * @ see #resetChoosableFileFilter
  754.      */ 
  755.     public void addChoosableFileFilter(FileFilter filter) {
  756.     if(!filters.contains(filter)) {
  757.         FileFilter[] oldValue = getChoosableFileFilters();
  758.         filters.addElement(filter);
  759.         firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
  760.     } 
  761.     }
  762.  
  763.     /**
  764.      * Removes a filter from the list of user choosable file filters. Returns
  765.      * true if the file filter was removed;
  766.      *
  767.      * @ see #addChoosableFileFilter
  768.      * @ see #getChoosableFileFilters
  769.      * @ see #resetChoosableFileFilter
  770.      */ 
  771.     public boolean removeChoosableFileFilter(FileFilter f) {
  772.     if(filters.contains(f)) {
  773.         FileFilter[] oldValue = getChoosableFileFilters();
  774.         filters.removeElement(f);
  775.         firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
  776.         return true;
  777.     } else {
  778.         return false;
  779.     }
  780.     }
  781.  
  782.     /**
  783.      * Resets the choosable file filter list to it's starting state. Normally,
  784.      * this removes all added file filters while leaving the AcceptAll file filter.
  785.      *
  786.      * @see #addChoosableFileFilter
  787.      * @see #getChoosableFileFilters
  788.      * @see #removeChoosableFileFilter
  789.      */
  790.     public void resetChoosableFileFilters() {
  791.     FileFilter[] oldValue = getChoosableFileFilters();
  792.     filters.removeAllElements();
  793.     filters.addElement(getAcceptAllFileFilter());
  794.     firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
  795.     }
  796.  
  797.     /**
  798.      * Returns the AcceptAll file filter (e.g. (All Files *.*) on windows).
  799.      */
  800.     public FileFilter getAcceptAllFileFilter() {
  801.     FileFilter filter = null;
  802.     if(getUI() != null) {
  803.         filter = getUI().getAcceptAllFileFilter(this);
  804.     }
  805.     return filter;
  806.     }
  807.  
  808.     /**
  809.      * Return the accessory component.
  810.      *
  811.      * @return this JFileChooser's accessory component, or null
  812.      * @see #setAccessory
  813.      */
  814.     public JComponent getAccessory() {
  815.         return accessory;
  816.     }
  817.  
  818.     /**
  819.      * Sets the accessory component. An accessory is often used to show a preview
  820.      * image of the selected file; however, it can be used for anything that
  821.      * the programmer wishes - such as extra custom file chooser controls.
  822.      *
  823.      * Note: if there was a previous accessory, you should unregister
  824.      * any listeners that the accessory might have registered with the
  825.      * file chooser.
  826.      *
  827.      * @beaninfo
  828.      *   preferred: true
  829.      *       bound: true
  830.      * description: Sets the accessory component on the FileChooser.
  831.      */
  832.     public void setAccessory(JComponent newAccessory) {
  833.         JComponent oldValue = accessory;
  834.         accessory = newAccessory;
  835.     firePropertyChange(ACCESSORY_CHANGED_PROPERTY, oldValue, accessory);
  836.     }
  837.     
  838.     /**
  839.      * Sets the FileChooser to allow the user to just select files, just select
  840.      * directories, or select both files and directetories.
  841.      *
  842.      * @beaninfo
  843.      *   preferred: true
  844.      *       bound: true
  845.      * description: Sets the types of files that the FileChooser can choose.
  846.      *        enum: FILES_ONLY JFileChooser.FILES_ONLY
  847.      *              DIRECTORIES_ONLY JFileChooser.DIRECTORIES_ONLY
  848.      *              FILES_AND_DIRECTORIES JFileChooser.FILES_AND_DIRECTORIES
  849.      *
  850.      * @param dialogType the type of dialog to be displayed:
  851.      *                   FILES_ONLY, DIRECTORIES_ONLY, FILES_AND_DIRECTORIES
  852.      *
  853.      * @see #getFileSelectionMode
  854.      */
  855.     public void setFileSelectionMode(int mode) {
  856.     if(fileSelectionMode == mode) {
  857.         return;
  858.     }
  859.     int oldValue = fileSelectionMode;
  860.     fileSelectionMode = mode;
  861.     firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, oldValue, fileSelectionMode);
  862.     }
  863.  
  864.     /**
  865.      * Returns the current file-selection mode.
  866.      *
  867.      * @param an int indicating the type of dialog to be displayed:
  868.      *                   FILES_ONLY, DIRECTORIES_ONLY, FILES_AND_DIRECTORIES
  869.      * @see #setFileSelectionMode
  870.      */
  871.     public int getFileSelectionMode() {
  872.     return fileSelectionMode;
  873.     }
  874.  
  875.     /**
  876.      * Convenience call that determines if files are selectable based on the current
  877.      * file selection mode
  878.      *
  879.      * @see #setFileSelectionMode
  880.      * @see #getFileSelectionMode
  881.      */
  882.     public boolean isFileSelectionEnabled() {
  883.     return ((fileSelectionMode == FILES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
  884.     }
  885.  
  886.     /**
  887.      * Convenience call that determines if directories are selectable based on the current
  888.      * file selection mode
  889.      *
  890.      * @see #setFileSelectionMode
  891.      * @see #getFileSelectionMode
  892.      */
  893.     public boolean isDirectorySelectionEnabled() {
  894.     return ((fileSelectionMode == DIRECTORIES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
  895.     }
  896.  
  897.     /**
  898.      * Sets the filechooser to allow multiple file selections.
  899.      * NOTE: this functionality is not yet implemented in the current L&Fs.
  900.      *
  901.      * @beaninfo
  902.      *       bound: true
  903.      * description: Sets multiple file selection mode
  904.      *
  905.      * @see #isMultiSelectionEnabled
  906.      */
  907.     public void setMultiSelectionEnabled(boolean b) {
  908.     if(multiSelectionEnabled == b) {
  909.         return;
  910.     }
  911.     boolean oldValue = multiSelectionEnabled;
  912.     multiSelectionEnabled = b;
  913.     firePropertyChange(MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, oldValue, multiSelectionEnabled);
  914.     }
  915.  
  916.     /**
  917.      * Returns true if multiple files can be selected.
  918.      * @return true if multiple files can be selected.
  919.      * @see #setMultiSelectionEnabled
  920.      */
  921.     public boolean isMultiSelectionEnabled() {
  922.     return multiSelectionEnabled;
  923.     }
  924.  
  925.     
  926.     /**
  927.      * If true, hidden files are not shown in the filechooser
  928.      *
  929.      * @return the status of the file hiding property
  930.      * @see #setFileHidingEnabled
  931.      */
  932.     public boolean isFileHidingEnabled() {
  933.     return useFileHiding;
  934.     }
  935.  
  936.     /**
  937.      * Sets file hiding on or off. If true, hidden files are not shown
  938.      * in the filechooser. The job of determining which files are
  939.      * show is done by the FileView.
  940.      *
  941.      * @beaninfo
  942.      *   preferred: true
  943.      *       bound: true
  944.      * description: Sets file hiding on or off.
  945.      *
  946.      * @param b the boolean value that determines whether file hiding is
  947.      *          turned on or not.
  948.      * @see #isFileHidingEnabled
  949.      */
  950.     public void setFileHidingEnabled(boolean b) {
  951.     boolean oldValue = useFileHiding;
  952.     useFileHiding = b;
  953.     firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, oldValue, useFileHiding);
  954.     }
  955.  
  956.     /**
  957.      * Sets the current File Filter. The file filter is used by the
  958.      * filechooser to filter out files from view from the user.
  959.      *
  960.      * @beaninfo
  961.      *   preferred: true
  962.      *       bound: true
  963.      * description: Sets the File Filter used to filter out files of type.
  964.      *
  965.      * @param filter the new current file filter to use
  966.      * @see #getFileFilter
  967.      */
  968.     public void setFileFilter(FileFilter filter) {
  969.     FileFilter oldValue = fileFilter;
  970.     fileFilter = filter;
  971.     firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, oldValue, fileFilter);
  972.     }
  973.     
  974.  
  975.     /**
  976.      * Returns the currently selected file filter.
  977.      *
  978.      * @return the current file filter.
  979.      * @see #setFileFilter
  980.      * @see #addChoosableFileFilter
  981.      */
  982.     public FileFilter getFileFilter() {
  983.     return fileFilter;
  984.     }
  985.  
  986.     /**
  987.      * Sets the file view to used to retrieve UI information, such as
  988.      * the icon that represents a file or the type description of a file.
  989.      *
  990.      * @beaninfo
  991.      *   preferred: true
  992.      *       bound: true
  993.      * description: Sets the File View used to get file type information
  994.      *
  995.      * @see #getFileView
  996.      */
  997.     public void setFileView(FileView fileView) {
  998.     FileView oldValue = this.fileView;
  999.     this.fileView = fileView;
  1000.     firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, oldValue, fileView);
  1001.     }
  1002.  
  1003.     /**
  1004.      * Returns the current file view.
  1005.      *
  1006.      * @see #setFileView
  1007.      */
  1008.     public FileView getFileView() {
  1009.     return fileView;
  1010.     }
  1011.     
  1012.     // ******************************
  1013.     // *****FileView delegation *****
  1014.     // ******************************
  1015.  
  1016.     // NOTE: all of the following methods attempt to delegate
  1017.     // first to the client set fileView, and if null is returned
  1018.     // (or there is now client defined fileView) then calls the
  1019.     // UI's default fileView.
  1020.     
  1021.     /**
  1022.      * Returns the file name.
  1023.      * @see FileView#getName
  1024.      */
  1025.     public String getName(File f) {
  1026.     String filename = null;
  1027.     if(getFileView() != null) {
  1028.         filename = getFileView().getName(f);
  1029.     }
  1030.     if(filename == null && uiFileView != null) {
  1031.         filename = uiFileView.getName(f);
  1032.     }
  1033.     return filename;
  1034.     }
  1035.  
  1036.     /**
  1037.      * Returns the file description.
  1038.      * @see FileView#getDescription
  1039.      */
  1040.     public String getDescription(File f) {
  1041.     String description = null;
  1042.     if(getFileView() != null) {
  1043.         description = getFileView().getDescription(f);
  1044.     }
  1045.     if(description == null && uiFileView != null) {
  1046.         description = uiFileView.getDescription(f);
  1047.     }
  1048.     return description;
  1049.     }
  1050.  
  1051.     /**
  1052.      * Returns the file type.
  1053.      * @see FileView#getTypeDescription
  1054.      */
  1055.     public String getTypeDescription(File f) {
  1056.     String typeDescription = null;
  1057.     if(getFileView() != null) {
  1058.         typeDescription = getFileView().getTypeDescription(f);
  1059.     }
  1060.     if(typeDescription == null && uiFileView != null) {
  1061.         typeDescription = uiFileView.getTypeDescription(f);
  1062.     }
  1063.     return typeDescription;
  1064.     }
  1065.  
  1066.     /**
  1067.      * Returns the icon for this file or type of file, depending
  1068.      * on the system.
  1069.      * @see FileView#getIcon
  1070.      */
  1071.     public Icon getIcon(File f) {
  1072.     Icon icon = null;
  1073.     if(getFileView() != null) {
  1074.         icon = getFileView().getIcon(f);
  1075.     }
  1076.     if(icon == null && uiFileView != null) {
  1077.         icon = uiFileView.getIcon(f);
  1078.     }
  1079.     return icon;
  1080.     }
  1081.  
  1082.     /**
  1083.      * Returns true if the file (directory) can be visited.
  1084.      * Returns false if the directory cannot be traversed.
  1085.      * @see FileView#isTraversable
  1086.      */
  1087.     public boolean isTraversable(File f) {
  1088.     Boolean traversable = null;
  1089.     if(getFileView() != null) {
  1090.         traversable = getFileView().isTraversable(f);
  1091.     }
  1092.     if(traversable == null && uiFileView != null) {
  1093.         traversable = uiFileView.isTraversable(f);
  1094.     }
  1095.     if(traversable == null && f != null) {
  1096.         if(f.isDirectory()) {
  1097.         traversable = Boolean.TRUE;
  1098.         } else {
  1099.         traversable = Boolean.FALSE;
  1100.         }
  1101.     } else if(traversable == null) {
  1102.         return false;
  1103.     }
  1104.     return traversable.booleanValue();
  1105.     }
  1106.  
  1107.     /**
  1108.      * Returns true if the file should be displayed.
  1109.      * @see FileFilter#accept
  1110.      */
  1111.     public boolean accept(File f) {
  1112.     boolean shown = true;
  1113.     if(fileFilter != null) {
  1114.         shown = fileFilter.accept(f);
  1115.     }
  1116.     return shown;
  1117.     }
  1118.  
  1119.     /**
  1120.      * Sets the file system view which the JFileChooser uses to
  1121.      * access and create file system resouces, such as finding
  1122.      * the floppy drive and getting a list of root drives.
  1123.      *
  1124.      * @beaninfo
  1125.      *      expert: true
  1126.      *       bound: true
  1127.      * description: Sets the FileSytemView used to get filesystem information
  1128.      *
  1129.      * @see FileSystemView
  1130.      */
  1131.     public void setFileSystemView(FileSystemView fsv) {
  1132.     FileSystemView oldValue = fileSystemView;
  1133.     fileSystemView = fsv;
  1134.     firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, oldValue, fileSystemView);
  1135.     }
  1136.  
  1137.     /**
  1138.      * Returns the file system view.
  1139.      * @return the FileSystemView object
  1140.      * @see #setFileSystemView
  1141.      */
  1142.     public FileSystemView getFileSystemView() {
  1143.     return fileSystemView;
  1144.     }
  1145.  
  1146.     // **************************
  1147.     // ***** Event Handling *****
  1148.     // **************************
  1149.  
  1150.     /**
  1151.      * Called by the UI when the user hits the approve
  1152.      * (AKA "Open" or "Save") button. This can also by
  1153.      * called by the programmer.
  1154.      */
  1155.     public void approveSelection() {
  1156.     returnValue = APPROVE_OPTION;
  1157.     if(dialog != null) {
  1158.         dialog.setVisible(false);
  1159.     }
  1160.     fireActionPerformed(APPROVE_SELECTION);
  1161.     }
  1162.  
  1163.     /**
  1164.      * Called by the UI when the user hits the cancel button.
  1165.      * This can also be called by the programmer.
  1166.      */
  1167.     public void cancelSelection() {
  1168.     returnValue = CANCEL_OPTION;
  1169.     if(dialog != null) {
  1170.         dialog.setVisible(false);
  1171.     }
  1172.     fireActionPerformed(CANCEL_SELECTION);
  1173.     }
  1174.  
  1175.     /**
  1176.      * adds an ActionListener to the button
  1177.      */
  1178.     public void addActionListener(ActionListener l) {
  1179.         listenerList.add(ActionListener.class, l);
  1180.     }
  1181.  
  1182.     /**
  1183.      * removes an ActionListener from the button
  1184.      */
  1185.     public void removeActionListener(ActionListener l) {
  1186.         listenerList.remove(ActionListener.class, l);
  1187.     }
  1188.  
  1189.     /**
  1190.      * Notify all listeners that have registered interest for
  1191.      * notification on this event type. The event instance
  1192.      * is lazily created using the parameters passed into
  1193.      * the fire method.
  1194.      * @see EventListenerList
  1195.      */
  1196.     protected void fireActionPerformed(String command) {
  1197.         // Guaranteed to return a non-null array
  1198.         Object[] listeners = listenerList.getListenerList();
  1199.         ActionEvent e = null;
  1200.         // Process the listeners last to first, notifying
  1201.         // those that are interested in this event
  1202.         for (int i = listeners.length-2; i>=0; i-=2) {
  1203.             if (listeners[i]==ActionListener.class) {
  1204.                 // Lazily create the event:
  1205.                 if (e == null) {
  1206.                     e = new ActionEvent(this,
  1207.                                         ActionEvent.ACTION_PERFORMED,
  1208.                                         command);
  1209.                 }
  1210.                 ((ActionListener)listeners[i+1]).actionPerformed(e);
  1211.             }
  1212.         }
  1213.     }
  1214.  
  1215.     // *********************************
  1216.     // ***** Pluggable L&F methods *****
  1217.     // *********************************
  1218.  
  1219.     /**
  1220.      * Notification from the UIFactory that the L&F
  1221.      * has changed.
  1222.      *
  1223.      * @see JComponent#updateUI
  1224.      */
  1225.     public void updateUI() {
  1226.     FileChooserUI ui = ((FileChooserUI)UIManager.getUI(this));
  1227.         setUI(ui);
  1228.  
  1229.     uiFileView = getUI().getFileView(this);
  1230.     boolean useAcceptAllFileFilter = removeChoosableFileFilter(getAcceptAllFileFilter());
  1231.     if(useAcceptAllFileFilter) {
  1232.         addChoosableFileFilter(getAcceptAllFileFilter());
  1233.     }
  1234.     }
  1235.  
  1236.     /**
  1237.      * Returns a string that specifies the name of the L&F class
  1238.      * that renders this component.
  1239.      *
  1240.      * @return "ButtonUI"
  1241.      * @see JComponent#getUIClassID
  1242.      * @see UIDefaults#getUI
  1243.      * @beaninfo
  1244.      *        expert: true
  1245.      *   description: A string that specifies the name of the L&F class.
  1246.      */
  1247.     public String getUIClassID() {
  1248.         return uiClassID;
  1249.     }
  1250.  
  1251.     /**
  1252.      * Gets the UI object which implements the L&F for this component.
  1253.      *
  1254.      * @return the FileChooserUI object that implements the FileChooserUI L&F
  1255.      */
  1256.     public FileChooserUI getUI() {
  1257.         return (FileChooserUI) ui;
  1258.     }
  1259.  
  1260.     /** 
  1261.      * See readObject() and writeObject() in JComponent for more 
  1262.      * information about serialization in Swing.
  1263.      */
  1264.     private void writeObject(ObjectOutputStream s) throws IOException {
  1265.         s.defaultWriteObject();
  1266.     if ((ui != null) && (getUIClassID().equals(uiClassID))) {
  1267.         ui.installUI(this);
  1268.     }
  1269.     }
  1270.  
  1271.  
  1272.     /**
  1273.      * Returns a string representation of this JFileChooser. This method 
  1274.      * is intended to be used only for debugging purposes, and the 
  1275.      * content and format of the returned string may vary between      
  1276.      * implementations. The returned string may be empty but may not 
  1277.      * be <code>null</code>.
  1278.      * <P>
  1279.      * Overriding paramString() to provide information about the
  1280.      * specific new aspects of the JFC components.
  1281.      * 
  1282.      * @return  a string representation of this JFileChooser.
  1283.      */
  1284.     protected String paramString() {
  1285.         String approveButtonTextString = (approveButtonText != null ?
  1286.                       approveButtonText: "");
  1287.         String dialogTitleString = (dialogTitle != null ?
  1288.                     dialogTitle: "");
  1289.         String dialogTypeString;
  1290.         if (dialogType == OPEN_DIALOG) {
  1291.             dialogTypeString = "OPEN_DIALOG";
  1292.         } else if (dialogType == SAVE_DIALOG) {
  1293.             dialogTypeString = "SAVE_DIALOG";
  1294.         } else if (dialogType == CUSTOM_DIALOG) {
  1295.             dialogTypeString = "CUSTOM_DIALOG";
  1296.         } else dialogTypeString = "";
  1297.         String returnValueString;
  1298.         if (returnValue == CANCEL_OPTION) {
  1299.             returnValueString = "CANCEL_OPTION";
  1300.         } else if (returnValue == APPROVE_OPTION) {
  1301.             returnValueString = "APPROVE_OPTION";
  1302.         } else if (returnValue == ERROR_OPTION) {
  1303.             returnValueString = "ERROR_OPTION";
  1304.         } else returnValueString = "";
  1305.         String useFileHidingString = (useFileHiding ?
  1306.                                     "true" : "false");
  1307.         String fileSelectionModeString;
  1308.         if (fileSelectionMode == FILES_ONLY) {
  1309.             fileSelectionModeString = "FILES_ONLY";
  1310.         } else if (fileSelectionMode == DIRECTORIES_ONLY) {
  1311.             fileSelectionModeString = "DIRECTORIES_ONLY";
  1312.         } else if (fileSelectionMode == FILES_AND_DIRECTORIES) {
  1313.             fileSelectionModeString = "FILES_AND_DIRECTORIES";
  1314.         } else fileSelectionModeString = "";
  1315.         String currentDirectoryString = (currentDirectory != null ?
  1316.                      currentDirectory.toString() : "");
  1317.         String selectedFileString = (selectedFile != null ?
  1318.                      selectedFile.toString() : "");
  1319.  
  1320.         return super.paramString() +
  1321.         ",approveButtonText=" + approveButtonTextString +
  1322.         ",currentDirectory=" + currentDirectoryString +
  1323.         ",dialogTitle=" + dialogTitleString +
  1324.         ",dialogType=" + dialogTypeString +
  1325.         ",fileSelectionMode=" + fileSelectionModeString +
  1326.         ",returnValue=" + returnValueString +
  1327.         ",selectedFile=" + selectedFileString +
  1328.         ",useFileHiding=" + useFileHidingString;
  1329.     }
  1330.  
  1331. /////////////////
  1332. // Accessibility support
  1333. ////////////////
  1334.  
  1335.     protected AccessibleContext accessibleContext = null;
  1336.  
  1337.     /**
  1338.      * Get the AccessibleContext associated with this JFileChooser
  1339.      *
  1340.      * @return the AccessibleContext of this JFileChooser
  1341.      */
  1342.     public AccessibleContext getAccessibleContext() {
  1343.         if (accessibleContext == null) {
  1344.             accessibleContext = new AccessibleJFileChooser();
  1345.         }
  1346.         return accessibleContext;
  1347.     }
  1348.  
  1349.     /**
  1350.      * The class used to obtain the accessible context for this object.
  1351.      */
  1352.     protected class AccessibleJFileChooser extends AccessibleJComponent {
  1353.  
  1354.         /**
  1355.          * Get the role of this object.
  1356.          *
  1357.          * @return an instance of AccessibleRole describing the role of the 
  1358.          * object
  1359.          * @see AccessibleRole
  1360.          */
  1361.         public AccessibleRole getAccessibleRole() {
  1362.             return AccessibleRole.FILE_CHOOSER;
  1363.         }
  1364.  
  1365.     } // inner class AccessibleJFileChooser
  1366.  
  1367. }
  1368.